package com.audaque.cloud.iqs;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.File;
import java.util.Properties;


@Getter
@Setter
@SuppressFBWarnings(value = {"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
@NoArgsConstructor
public class ZkHiveBean implements java.io.Serializable {

    private String zkQuorum;
    private String auth;
    private String saslQop;
    private String zooKeeperNamespace;
    private String serviceDiscoveryMode;
    private String principal;
    private String auditAddition;

    private String userName;
    private String url;
    private String driverClass;

    private File hiveClientFile;
    private File krb5confFile;
    private File keytabFile;

    private Properties clientInfo;

    public void buildUrl() {
        StringBuilder strBuilder = new StringBuilder("jdbc:hive2://").append(getZkQuorum()).append("/");
        if (HiveBuilder.HIVE_AUTH.equalsIgnoreCase(getAuth())) {
            strBuilder.append(";serviceDiscoveryMode=")
                    .append(getServiceDiscoveryMode())
                    .append(";zooKeeperNamespace=")
                    .append(getZooKeeperNamespace())
                    .append(";sasl.qop=")
                    .append(getSaslQop())
                    .append(";auth=")
                    .append(getAuth())
                    .append(";principal=")
                    .append(getPrincipal());
        } else {
            strBuilder.append(";serviceDiscoveryMode=")
                    .append(getServiceDiscoveryMode())
                    .append(";zooKeeperNamespace=")
                    .append(getZooKeeperNamespace())
                    .append(";auth=none");
        }
        if (getAuditAddition() != null && !getAuditAddition().isEmpty()) {
            strBuilder.append(";auditAddition=").append(getAuditAddition());
        }
        setUrl(strBuilder.toString());
    }
}
